<template>
  <div style="height: 100%; width: 100%; position: relative;" ref="maindev">
      <div class="pagetop" :style="{ height: OtherShow?'190px':'95px' }">
          <table style="width: 100%; font-size: 12px;" border="0">
              <col style="width: 5%;" />
              <col style="width: 8%;" />
              <col style="width: 1%;" />
              <col style="width: 8%;" />
              <col style="width: 4%;" />
              <col style="width: 11%;" />
              <col style="width: 4%;" />
              <col style="width: 11%;" />
              <col style="width: 59%;" />
              <tr>
                  <td align="right">
                      <el-dropdown @command="handleCommand" style="font-size: 12px;">
                          <u class="el-dropdown-link">
                              {{ datename }}
                          </u>
                          <el-dropdown-menu slot="dropdown">
                              <el-dropdown-item command="标本日期">
                                  <font font-size="12px">标本日期</font>
                              </el-dropdown-item>
                              <el-dropdown-item command="报告日期">
                                  <font font-size="12px">报告日期</font>
                              </el-dropdown-item>
                              <el-dropdown-item command="工作组签收日期">
                                  <font font-size="12px">工作组签收日期</font>
                              </el-dropdown-item>
                          </el-dropdown-menu>
                      </el-dropdown>
                  </td>
                  <td>
                      <el-date-picker v-model="searchobj.strdate" :clearable="false" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 100%;"> </el-date-picker>
                  </td>
                  <td>至</td>
                  <td>
                      <el-date-picker v-model="searchobj.enddate" type="date" :clearable="false" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 100%;"> </el-date-picker>
                  </td>
                  <td align="right">报告单元</td>
                  <td colspan="1">
                      <el-select v-model="searchobj.rptunitid" @dblclick.native="popMultipleChk(searchobj.rptunitid, 'rptunitid', rptunitOption, '请选择报告单元')" filterable clearable style="width:100%">
                          <el-option v-for="(item, index) in rptunitOption" :key="index" :value="item.data" :label="item.display"></el-option>
                      </el-select>
                  </td>
                  <td align="right">急诊标志</td>
                  <td>
                      <el-select v-model="searchobj.emer_flag" placeholder="请选择" style="width:100%">
                          <el-option key="all" label="全部" value="all"></el-option>
                          <el-option key="0" label="常规" value="0"></el-option>
                          <el-option key="1" label="加急" value="1"></el-option>
                      </el-select>
                  </td>
                  <td></td>
              </tr>
              <tr v-show="OtherShow">
                  <td align="right">接收时间</td>
                  <td colspan="3">
                      <el-time-picker v-model="searchobj.strtime" placeholder="开始时间" style="width:38%" value-format="HH:mm" format='HH:mm'></el-time-picker> 至
                      <el-time-picker v-model="searchobj.endtime" placeholder="结束时间" style="width:38%" value-format="HH:mm" format='HH:mm'></el-time-picker>
                      <el-checkbox style="width:16%; align:right" true-label="1" false-label="0" v-model="searchobj.exceptflag">&nbsp;剔除</el-checkbox>
                  </td>
                  <!-- <td align="right">单元组合</td>
                  <td>
                     <el-input v-model="searchobj.XXdanyuanzuhe" placeholder="请填写"></el-input>
                  </td> -->
                  <td align="right">科室</td>
                  <td colspan="1">
                      <el-select v-model="searchobj.reqdept" @dblclick.native="popMultipleChk(searchobj.reqdept, 'reqdept', deptOption, '申请科室选择')" style="width: 100%;" filterable clearable>
                          <el-option v-for="(item, index) in deptOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                      </el-select>
                  </td>
                  <td align="right">病人类型</td>
                  <td>
                      <rm-ddl-common datatype="seccode" kindno="PT" dataname="病人类型" v-model="searchobj.pattype" width="100%" @change="pattypeChange"></rm-ddl-common>
                  </td>
              </tr>
              <tr v-show="OtherShow">
                  <td></td>
                  <td colspan="2">
                      <el-checkbox style="width:15%; align:right;font-size:12px" true-label="1" false-label="0" v-model="searchobj.nullflag">剔除待查原因不为空的项目</el-checkbox>
                  </td>
                  <td>
                      <el-popover placement="bottom-end" width="110" trigger="click">
                          <el-checkbox style=" font-size=12px" true-label="1" false-label="0" v-model="otherTAT.cp_tatsmpd2send">采样到送出</el-checkbox>
                          <el-checkbox style=" font-size=12px" true-label="1" false-label="0" v-model="otherTAT.cp_tatsend2arr">送出到送达</el-checkbox>
                          <el-checkbox style="font-size=12px" true-label="1" false-label="0" v-model="otherTAT.cp_tatarr2rcv">送达到接收</el-checkbox>
                          <el-checkbox style="font-size=12px" true-label="1" false-label="0" v-model="otherTAT.cp_tatreceive2input">接收到录入</el-checkbox>
                          <el-checkbox style="font-size=12px" true-label="1" false-label="0" v-model="otherTAT.cp_tatinput2report">录入到报告</el-checkbox>
                          <el-checkbox style="font-size=12px" true-label="1" false-label="0" v-model="otherTAT.cp_tatreq2report">申请到报告</el-checkbox>
                          <el-link type="primary" :underline="true" style="font-size: 12px;" slot="reference">{{ "其他TAT统计项目" }}</el-link>
                      </el-popover>
                  </td>
                  <td align="right">送检医院</td>
                  <td>
                      <el-select v-model="searchobj.hospcode" @dblclick.native="popMultipleChk(searchobj.hospcode,'hospcode',hospOption,'请选择送检医院')" filterable clearable style="width:100%">
                          <el-option v-for="(item,index) in hospOption" :key="index" :value="item.data" :label="item.display"></el-option>
                      </el-select>
                  </td>
                  <td align="right">检验医院</td>
                  <td>
                      <el-select v-model="searchobj.labhospital" @dblclick.native="popMultipleChk(searchobj.labhospital,'labhospital',hospOption,'请选择检验医院')" filterable clearable style="width:100%">
                          <el-option v-for="(item,index) in hospOption" :key="index" :value="item.data" :label="item.display"></el-option>
                      </el-select>
                  </td>
              </tr>
              <tr v-show="OtherShow">
                  <td></td>
                  <td colspan="2">
                      <el-checkbox style="width:15%; align:right;font-size:12px" true-label="1" false-label="0" v-model="searchobj.recieve_report">仅统计当天接收当天报告的标本</el-checkbox>
                  </td>
                  <td>
                  </td>
                  <td align="right">送检医生</td>
                  <td>
                      <rm-ddl-common datatype="doctor" dataname="送检医生" v-model="searchobj.reqdocno" width="100%" @change="reqdocCHange"></rm-ddl-common>
                  </td>
                  <td align="right">检验医生</td>
                  <td>
                      <rm-ddl-common datatype="userinfo" dataname="检验医生" v-model="searchobj.reportuser" width="100%" @change="reportuserChange"></rm-ddl-common>
                  </td>
              </tr>
              <tr>
                  <td align="right"><span @click="Btncountitem" style="color:#F56C6C;font-weight:bold;boder-color:#DCDFE6;cursor: pointer;font: size 14px;">统计项目</span></td>
                  <td @click="Btncountitem" style="height:26px;color:#409EFF;font-weight:bold;border: 1px solid #DCDFE6;cursor: pointer;" colspan="7" ref="countitem">
                      <div style="text-align:center;" v-if="infocode==''" @click="Btncountitem">
                          <span style="color:#F56C6C;cursor:pointer;font-weight:bold;font-size:13px"> 点击此处选择统计项目</span>
                      </div>
                      <div v-else>
                          <div @click="Btncountitem" style="width:100%;height: 100%;"> <u style="0 0 0 5px">{{ infoitem }}</u>
                          </div>
                          <el-input v-model="infocode" readonly v-show="false"></el-input>
                      </div>
                  </td>
              </tr>
              <tr>
                  <td colspan="14" align="right">
                      <el-link :underline="false" @click="OtherShow = !OtherShow">{{ OtherShow?"收起▲":"展开▼" }}</el-link>
                      <el-button @click.native="btnQuery" v-has="'PINQUERY'" type="primary" icon="el-icon-search">查询</el-button>
                      <!-- <el-button @click.native="btnSort" icon="el-icon-sort">排序</el-button> -->
                      <el-button @click.native="btnClear" icon="el-icon-close">清除</el-button>
                      <el-button @click.native="BtnExport" icon="el-icon-upload2">导出</el-button>
                  </td>
              </tr>
          </table>
      </div>
      <div class="pagecenter" :style="{ top: OtherShow?'195px':'100px' }">
          <div class="middle-center">
              <vxe-table :data.sync="tableData" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="100%" highlight-current-row class="mytable-style" highlight-hover-column highlight-hover-row ref="xTable" resizable size="mini" stripe :optimization="{ animat: true }" header-align="center" :key="xTablekey" show-footer :footer-method="footerMethod" :loading="bLoading" :cell-class-name="CellClassName" :footer-cell-class-name="footerCellClassName" show-overflow="tooltip">
                  <vxe-table-column :field="items.field" :key="items.title" :title="items.title" :width="items.width" sortable align="center" v-for="items in tableColumn" :formatter="formatFun"></vxe-table-column>
                  <vxe-table-column field="cp_samplecnt" sortable title="样本人次" width="80" header-align="center" align="right"></vxe-table-column>
                  <vxe-table-column field="cp_sampled" sortable title="申请-采样" width="80" header-align="center" align="right"></vxe-table-column>
                  <vxe-table-column field="cp_recieve" sortable title="采样-接收" width="80" header-align="center" align="right"></vxe-table-column>
                  <vxe-table-column field="cp_report" sortable title="接收-报告" width="80" header-align="center" align="right"></vxe-table-column>
                  <vxe-table-column field="samptorep" sortable title="采样-报告" width="80" header-align="center" align="right"></vxe-table-column>
                  <vxe-table-column :field="items.field" :key="items.title" :title="items.title" :width="items.width" sortable header-align="center" align="right" v-for="items in otherTableColumn" :formatter="formatFun"></vxe-table-column>
              </vxe-table>
          </div>
      </div>
      <!--报告项目--->
      <el-dialog width="1000px" top="10px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="报告项目" :visible.sync="dialogTableVisible1" :destroy-on-close="true">
          <rm-pop-selrptitem @cancel="dialogTableVisible1 = false" @selitem="addrptitem"></rm-pop-selrptitem>
      </el-dialog>
      <!--多选弹窗--->
      <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle" :visible.sync="dialogMultipleVisible" :destroy-on-close="true">
          <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname" @change="closedialog"></rm-SqlMultiple>
      </el-dialog>
      <!-- 统计项目 -->
      <!--统计项目-->
      <el-dialog title="统计项目" :visible.sync="dialogcountItem" width="800px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false">
          <div style="width: 100%; height: 300px; margin-top: 5px;">
              <div style="width: 70%; height: 100%; float: left; overflow: auto; border: 1px solid #ccc;">
                  <div id="left_nav" class="left_nav">

                      <div @click="showseq = 1" :class="showseq == 1 ? 'active' : ''" ref="left1">
                          1 检验信息
                      </div>
                  </div>
                  <div id="right_nav" class="right_nav">
                      <table class="table1style" style="width: 100%; padding: 10px;">
                          <tr v-show="showseq == 1">
                              <td>
                                  <el-checkbox @change="chkcountitem($event, '病人类型', 'rp_pat_typecode')" v-model="rp_pat_typecode">病人类型</el-checkbox>
                              </td>
                              <td>
                                  <el-checkbox @change="chkcountitem($event, '所属病区', 'rp_req_wardno')" v-model="rp_req_wardno">所属病区</el-checkbox>
                              </td>
                              <td>
                                  <el-checkbox @change="chkcountitem($event, '申请科室', 'rp_req_deptno')" v-model="rp_req_deptno">申请科室</el-checkbox>
                              </td>
                          </tr>
                          <tr v-show="showseq == 1">
                              <td>
                                  <el-checkbox @change="chkcountitem($event, '标本', 'rp_specimen_code')" v-model="rp_specimen_code">标本</el-checkbox>
                              </td>
                              <td>
                                  <el-checkbox @change="chkcountitem($event, '项目', 'rp_req_itemname')" v-model="rp_req_itemname">项目</el-checkbox>
                              </td>
                              <td>
                                  <el-checkbox @change="chkcountitem($event, '分单类别', 'rp_req_groupna')" v-model="rp_req_groupna">分单类别</el-checkbox>
                              </td>
                          </tr>
                          <tr v-show="showseq == 1">
                              <td>
                                  <el-checkbox @change="chkcountitem($event, '年', 'rp_sampleyear')" v-model="rp_sampleyear">年(YYYY)</el-checkbox>
                              </td>
                              <td>
                                  <el-checkbox @change="chkcountitem($event, '月', 'rp_samplemonth')" v-model="rp_samplemonth">月(YYYYMM)</el-checkbox>
                              </td>
                              <td>
                                  <el-checkbox @change="chkcountitem($event, '日', 'rp_sampleday')" v-model="rp_sampleday">日(YYYY/MM/dd)</el-checkbox>
                              </td>
                          </tr>
                          <tr v-show="showseq == 1">
                              <td>
                                  <el-checkbox @change="chkcountitem($event, '病人', 'rp_pat_name')" v-model="rp_pat_name">病人</el-checkbox>
                              </td>
                          </tr>
                      </table>
                  </div>
              </div>
              <div style="width: 29%; height: 100%; float: left; margin-left: 5px; overflow: auto;">
                  <vxe-table show-overflow ref="xTable1" height="auto" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" :mouse-config="{ selected: true }" :data.sync="tableData1" border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe @current-change="currentChangeEvent1" @cell-dblclick="xTable1dblclick">
                      <vxe-table-column type="index" title="NO." width="50" align="center"></vxe-table-column>
                      <vxe-table-column field="countitem" title="统计项目(双击删除)" width="160" sortable header-align="center"></vxe-table-column>
                  </vxe-table>
              </div>
          </div>
          <span slot="footer" class="dialog-footer">
              <el-button icon="el-icon-top" @click="tabledatafirst()">首位</el-button>
              <el-button icon="el-icon-top-right" @click="tabledataup()">上移</el-button>
              <el-button icon="el-icon-bottom-right" @click="tabledatadown()">下移</el-button>
              <el-button icon="el-icon-bottom" @click="tabledatalast()">末位</el-button>
              <el-button @click="tableClear">清 除</el-button>
              <el-button type="primary" @click="dialogcountItemsave">确 定</el-button>
              <el-button @click="dialogcountItem = false">取 消</el-button>
          </span>
      </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  name: "LIS651",
  data() {
      return {
          bLoading: false,
          OtherShow: false,
          rp_pat_name: false, 
          rp_pat_no: false,
          rp_pat_typecode: false,
          rp_req_deptno: false,
          rp_req_wardno: false,
          rp_specimen_code: false,
          rp_req_itemname: false,
          rp_req_groupna: false,
          rp_sampleyear: false,
          rp_samplemonth: false,
          rp_sampleday: false,
          is_showselother: false,
          dialogcountItem: false,
          dialogTableVisible1: false,
          dialogMultipleVisible: false,
          daytype: "1",
          infoitem: "",
          infocode: "",
          txtrptitem: "",
          fieldname: "",
          datename: "标本日期",
          multichktitle: "",
          showseq: 1,
          currRowIndex: 0,
          xTablekey: 0,
          option1: [],
          option2: [],
          tableData: [],
          tableData1: [],
          deptOption: [],
          hospOption: [],
          wardOption: [],
          tableColumn: [],
          doctorOption: [],
          rptunitOption: [],
          otherTableColumn: [], //其他TAT统计列
          otherTAT: {
              cp_tatsmpd2send: "0",
              cp_tatsend2arr: "0",
              cp_tatarr2rcv: "0",
              cp_tatreceive2input: "0",
              cp_tatinput2report: "0",
              cp_tatreq2report: "0",
          },
          avg: {
              //样本总数+平均值
              sampcnt: 0,
              avg_cp_sampled: 0,
              avg_cp_recieve: 0,
              avg_cp_report: 0,
              avg_samptorep: 0,
              avg_cp_tatsmpd2send: 0,
              avg_cp_tatsend2arr: 0,
              avg_cp_tatarr2rcv: 0,
              avg_cp_tatreceive2input: 0,
              avg_cp_tatinput2report: 0,
              avg_cp_tatreq2report: 0,
          },
          searchobj: {
              //查询框初始值
              strdate: this.$pub.InitDateTime2(0).datefrom,
              enddate: this.$pub.InitDateTime2(0).dateto,
              rptunitid: "",
              emer_flag: "all",
              strtime: "00:00",
              endtime: "23:59",
              exceptflag: 0,
              XXdanyuanzuhe: "",
              pattype: "",
              reqdept: "",
              hospcode: "",
              labhospital: "",
              nullflag: "0",
              recieve_report: "0",
              reqdocno: "",
              reportuser: "",
          },
          sortArr: [],
          SortTableColumn: [
              { title: "报告数", field: "cp_samplecnt" },
              { title: "检验项目次数", field: "cp_cnt" },
              { title: "金额", field: "cp_amt" },
              { title: "人数", field: "cp_rs" },
              { title: "项目复查数", field: "cp_redocnt" },
          ],
          defaultColumn: [
              { title: "病人姓名", field: "rp_pat_name", width: "65", position: "center" },
              { title: "病历号", field: "rp_pat_no", width: "120", position: "left" },
              { title: "病人类型", field: "rp_pat_typecode", width: "65", position: "center" },
              { title: "科室", field: "rp_req_deptno", width: "100" },
              { title: "病区", field: "rp_req_wardno", width: "100" },
              { title: "样本类型", field: "rp_specimen_code", width: "80" },
              { title: "项目", field: "rp_req_itemname", width: "180" },
              { title: "分单类别", field: "rp_req_groupna", width: "80", position: "center" },
              { title: "年", field: "rp_sampleyear", width: "50", position: "center" },
              { title: "月", field: "rp_samplemonth", width: "60", position: "center" },
              { title: "日", field: "rp_sampleday", width: "80", position: "center" },
              { title: "采样-送出", field: "cp_tatsmpd2send", width: "80", position: "center" },
              { title: "送出-送达", field: "cp_tatsend2arr", width: "80", position: "center" },
              { title: "送达-接收", field: "cp_tatarr2rcv", width: "80", position: "center" },
              { title: "接收-录入", field: "cp_tatreceive2input", width: "80", position: "center" },
              { title: "录入-报告", field: "cp_tatinput2report", width: "80", position: "center" },
              { title: "申请-报告", field: "cp_tatreq2report", width: "80", position: "center" },
          ],
          pattypename: "",
          reqdocname: "",
          reportusername: "",
      };
  },
  created() {
      this.initOption();
      this.initdate(); //初始化时间
  },
  mounted() {},
  updated() {},
  methods: {
      popMultipleChk(e, fieldname, option, title) {
          let temp = XEUtils.clone(option, true);
          this.option1 = [];
          this.option2 = [];
          if (e != "") {
              let k = e.split(",");
              k.forEach((item) => {
                  let ndata = temp.find((m) => m.data == item);
                  if (ndata != undefined && ndata != null) {
                      this.option2.push(ndata);
                  }
              });
              temp.forEach((item) => {
                  if (k.indexOf(item.data + "") < 0) {
                      this.option1.push(item);
                  }
              });
          } else {
              this.option1 = temp;
          }
          this.fieldname = fieldname;
          this.multichktitle = title;
          this.dialogMultipleVisible = true;
      },
      closedialog(value, name) {
          if (value != "close") {
              this.searchobj[name] = value;
          }
          this.dialogMultipleVisible = false;
      },
      //时间初始化
      initdate() {
          var date = new Date();
          this.strdate = XEUtils.toDateString(date, "yyyy-MM-01 00:00:00"); //起 始结束日期
          this.enddate = XEUtils.toDateString(date, "yyyy-MM-dd 00:00:00");
      },
      Btncountitem() {
          //重置所有选项
          this.rp_pat_name = false;
          this.rp_pat_no = false;
          this.rp_pat_typecode = false;
          this.rp_req_deptno = false;
          this.rp_req_wardno = false;
          this.rp_specimen_code = false;
          this.rp_req_itemname = false;
          this.rp_req_groupna = false;
          this.rp_sampleyear = false;
          this.rp_samplemonth = false;
          this.rp_sampleday = false;

          this.dialogcountItem = true; //开窗
          //表格及checkbox重新赋值
          setTimeout(() => {
              this.$refs.xTable1.tableData = [];
              if (this.infoitem != "") {
                  let name = this.infoitem.split(",");
                  let code = this.infocode.split(",");
                  let datas = this.$refs.xTable1.tableData;
                  for (let i = 0; i < name.length; i++) {
                      let finddatas = datas.filter((item) => item.countitem == name[i]);
                      if (finddatas.length == 0) {
                          this.$refs.xTable1
                              .insert({
                                  countitem: name[i],
                                  countcode: code[i],
                              })
                              .then(({ row }) => {
                                  this.$refs.xTable1.setCurrentRow(row);
                              });
                          this.currRowIndex = name.length - 1;
                      }
                      this[code[i]] = true;
                  }
              }
          }, 20);
      },
      //选择统计项目
      chkcountitem(e, name, code) {
          let tablelist = this.$refs.xTable1.tableData;
          let ishave = tablelist.find((m) => m.countitem == name);
          if (e) {
              if (tablelist.length <= 9) {
                  if (ishave == undefined) {
                      //防止重复插入
                      this[code] = true;
                      this.$refs.xTable1.insert({ countitem: name, countcode: code }).then(({ row }) => {
                          this.$refs.xTable1.setCurrentRow(row);
                          this.currRowIndex = tablelist.length - 1;
                      });
                  }
              } else {
                  this[code] = false;
                  this.$alert("您好，最多只能添加10条统计项目！", "提示", {
                      confirmButtonText: "确定",
                  });
              }
          } else {
              try {
                  if (ishave != undefined) {
                      this[code] = false;
                      var alld = this.$refs.xTable1.tableData;
                      var rowindex = alld.indexOf(ishave);
                      this.$refs.xTable1.remove(ishave);
                      let havedata = this.$refs.xTable1.tableData;
                      if (havedata.length > 0) {
                          if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                          let selectrow = havedata[rowindex];
                          this.$refs.xTable1.setCurrentRow(selectrow);
                          this.currRowIndex = rowindex;
                      }
                  }
              } catch (e) {
                  console.log("error", e);
              }
          }
      },
      addrptitem(rptitemcodeinfos) {
          this.txtrptitem = "";
          for (var i = 0; i < rptitemcodeinfos.length; i++) {
              if (this.txtrptitem == "") {
                  this.txtrptitem = rptitemcodeinfos[i].rpt_itemcode;
              } else {
                  this.txtrptitem += "," + rptitemcodeinfos[i].rpt_itemcode;
              }
          }
          this.dialogTableVisible1 = false;
      },
      currentChangeEvent1({ row, $rowIndex }) {
          this.currRowIndex = $rowIndex;
      },
      tabledataup() {
          if (this.currRowIndex > 0) {
              let upData = this.$refs.xTable1.tableData[this.currRowIndex - 1];
              let currentrow = this.$refs.xTable1.tableData[this.currRowIndex];
              this.$refs.xTable1.tableData.splice(this.currRowIndex - 1, 1);
              this.$refs.xTable1.tableData.splice(this.currRowIndex, 0, upData);
              this.currRowIndex = this.currRowIndex - 1;
              this.$nextTick(() => {
                  this.$refs.xTable1.setCurrentRow(currentrow);
              });
          }
      },
      tabledatadown() {
          if (this.currRowIndex !== this.$refs.xTable1.tableData.length - 1) {
              let downData = this.$refs.xTable1.tableData[this.currRowIndex + 1];
              let currentrow = this.$refs.xTable1.tableData[this.currRowIndex];
              this.$refs.xTable1.tableData.splice(this.currRowIndex + 1, 1);
              this.$refs.xTable1.tableData.splice(this.currRowIndex, 0, downData);
              this.currRowIndex = this.currRowIndex + 1;
              this.$nextTick(() => {
                  this.$refs.xTable1.setCurrentRow(currentrow);
              });
          }
      },
      tabledatalast() {
          if (this.currRowIndex != this.$refs.xTable1.tableData.length - 1) {
              let lastData = this.$refs.xTable1.tableData[this.currRowIndex];
              this.$refs.xTable1.tableData.splice(this.currRowIndex, 1);
              this.$refs.xTable1.tableData.splice(this.$refs.xTable1.tableData.length, 0, lastData);
              this.currRowIndex = this.$refs.xTable1.tableData.length - 1;
              this.$nextTick(() => {
                  this.$refs.xTable1.setCurrentRow(lastData);
              });
          }
      },
      tabledatafirst() {
          if (this.currRowIndex > 0) {
              let firstData = this.$refs.xTable1.tableData[this.currRowIndex];
              this.$refs.xTable1.tableData.splice(this.currRowIndex, 1);
              this.$refs.xTable1.tableData.splice(0, 0, firstData);
              this.currRowIndex = 0;
              this.$nextTick(() => {
                  this.$refs.xTable1.setCurrentRow(firstData);
              });
          }
      },
      handleCommand(name) {
          this.datename = name;
          if (name == "标本日期") this.daytype = "1";
          else if (name == "报告日期") this.daytype = "2";
          else this.daytype = "3";
      },
      async initOption() {
          try {
              const res = await this.$tool.request({
                  url: "LIS/LIS6/LIS651",
                  method: "post",
                  data: {
                      action: "initoption",
                  },
              });
              this.deptOption = res.deptOption;
              res.hospOption.forEach((item)=>{
                  this.hospOption.push({data: item.value, display: item.label});
              });
              this.doctorOption = res.doctorOption;
              this.rptunitOption = res.rptunitOption;
              this.wardOption = res.wardOption;
              this.userOption = res.userOption;
          } catch (e) {
              this.$message.warning(e);
          }
      },
      btnQuery() {
          this.InitPage();
      },
      btnSort() {
          this.$rmsort(
              { tableColumn: this.SortTableColumn, sortArr: this.sortArr },
              {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
              }
          )
              .then((res) => {
                  this.sortArr = res.data;
                  this.InitPage();
              })
              .catch(() => {});
      },
      btnClear() {
          this.initdate();
          this.searchobj = {
              strdate: this.$pub.InitDateTime2(0).datefrom,
              enddate: this.$pub.InitDateTime2(0).dateto,
              strtime: "00:00",
              endtime: "23:59",
              reqdept: "",
              germcomb: "",
              resistrule: "",
              reqward: "",
              sample: "",
              rptunitid: "",
              deptgroup: "",
              patsex: "",
              pattype: "",
              bytype: "",
              bypat: "",
              nogermflag: "0",
              deptmode: "0",
              exceptflag:0,
          };
          this.otherTAT = {
              cp_tatsmpd2send: "0",
              cp_tatsend2arr: "0",
              cp_tatarr2rcv: "0",
              cp_tatreceive2input: "0",
              cp_tatinput2report: "0",
              cp_tatreq2report: "0",
          };
          this.avg = {
              //样本总数+平均值
              sampcnt: 0,
              avg_cp_sampled: 0,
              avg_cp_recieve: 0,
              avg_cp_report: 0,
              avg_samptorep: 0,
              avg_cp_tatsmpd2send: 0,
              avg_cp_tatsend2arr: 0,
              avg_cp_tatarr2rcv: 0,
              avg_cp_tatreceive2input: 0,
              avg_cp_tatinput2report: 0,
              avg_cp_tatreq2report: 0,
          };
          this.tableColumn = [];
          this.otherTableColumn = [];

          this.tableData = [];
      },
      pattypeChange(code,name) {
          this.searchobj.pattype = code;
          this.pattypename = name;
      },
      reqdocCHange(code,name) {
          this.searchobj.reqdocno = code;
          this.reqdocname = name;
      },
      reportuserChange(code,name) {
          this.searchobj.reportuser = code;
          this.reportusername = name;
      },
      BtnExport() {
          let exportColumn = [];
          let tableColumn = this.$refs.xTable.getColumns();
          tableColumn.forEach((item) => {
              exportColumn.push({ title: item.title, field: item.property });
          });
          let filtertxt = this.getExportFilter();
          this.$pub.exportTableExcel(this.tableData, exportColumn, "LIS651_TAT检验过程用时统计.xlsx", filtertxt, "统计条件：");
      },
      // 获取当前导出文件的所有查询条件
      getExportFilter() {
          let filtertxt = this.datename + ":" + XEUtils.toDateString(this.searchobj.strdate, "yyyy-MM-dd") + "至" + XEUtils.toDateString(this.searchobj.enddate, "yyyy-MM-dd") + "; ";
          if(this.searchobj.rptunitid) filtertxt += "报告单元:" + this.getOptionName(this.rptunitOption.filter((item) =>  ("," + this.searchobj.rptunitid + ",").indexOf("," + item.data + ",") > -1))+ "; ";
          filtertxt += "急诊标志:" + (this.searchobj.emer_flag == "all" ? "全部" : this.searchobj.emer_flag == "0" ? "急诊" : "常规") + "; ";
          let recdttxt = "";
          if(this.searchobj.exceptflag == "1") recdttxt += "剔除";
          if(this.searchobj.strtime) recdttxt += this.searchobj.strtime, "HH:mm";
          if(this.searchobj.endtime) recdttxt += "至" + this.searchobj.endtime, "HH:mm";
          if(recdttxt) filtertxt += "接收时间:" + recdttxt + "; ";
          if(this.searchobj.reqdept) filtertxt += "科室:" + this.getOptionName(this.deptOption.filter((item) =>  ("," + this.searchobj.reqdept + ",").indexOf("," + item.data + ",") > -1))+ "; ";
          if(this.searchobj.pattype)  filtertxt += "病人类型:" + this.pattypename + "; ";
          if(this.searchobj.nullflag == "1") filtertxt += "剔除待查原因不为空的项目;"
          let othertatitem = "";
          if(this.otherTAT.cp_tatsmpd2send == "1") othertatitem += "采样到送出、";
          if(this.otherTAT.cp_tatsmpd2send == "1") othertatitem += "送出到送达、";
          if(this.otherTAT.cp_tatsmpd2send == "1") othertatitem += "送达到接收、";
          if(this.otherTAT.cp_tatsmpd2send == "1") othertatitem += "接收到录入、";
          if(this.otherTAT.cp_tatsmpd2send == "1") othertatitem += "录入到报告、";
          if(this.otherTAT.cp_tatsmpd2send == "1") othertatitem += "申请到报告、";
          if(othertatitem) filtertxt += "其他TAT统计项目: " + othertatitem.substring(0, othertatitem.length - 1) + "; ";
          if(this.searchobj.hospcode) filtertxt += "送检医院:" + this.getOptionName(this.hospOption.filter((item) =>  ("," + this.searchobj.hospcode + ",").indexOf("," + item.data + ",") > -1))+ "; ";
          if(this.searchobj.labhospital) filtertxt += "检验医院:" + this.getOptionName(this.hospOption.filter((item) =>  ("," + this.searchobj.labhospital + ",").indexOf("," + item.data + ",") > -1))+ "; ";
          if(this.searchobj.recieve_report == "1") filtertxt += "仅统计当天接收当天报告的标本;"
          if(this.searchobj.reqdocno)  filtertxt += "送检医生:" + this.reqdocname + "; ";
          if(this.searchobj.reportuser)  filtertxt += "检验医生:" + this.reportusername + "; ";
          if(this.infocode)  filtertxt += "统计项目:" + this.infoitem + "; ";
          return filtertxt;
      },
      getOptionName(option) {
          if (option && option.length > 0) {
              let optionname = "";
              option.forEach((item) => {
                  if(item.hasOwnProperty("display")) {
                      optionname += item.display + ",";
                  } else {
                      optionname += item.label + ",";
                  }
              });
              return optionname.substring(0, optionname.length - 1);
          } else {
              return "";
          }
      },
      async InitPage() {
          this.sampcnt = 0;
          this.avg_cp_sampled = 0;
          this.avg_cp_recieve = 0;
          this.avg_cp_report = 0;
          this.avg_samptorep = 0;
          if (this.searchobj.rptunitid == "" && this.infoitem == "") {
              this.$alert("请您先选择<b style='color:#F56C6C'>报告单元</b>与<b style='color:#F56C6C'>统计项目</b>。", "提示", { dangerouslyUseHTMLString: true, type: "info" });
              return false;
          }
          if (this.searchobj.rptunitid == "") {
              this.$alert("请您先选择<b style='color:#F56C6C'>报告单元</b>。", "提示", { dangerouslyUseHTMLString: true, type: "info" });
              return false;
          }
          if (this.infoitem == "") {
              this.$alert("请您先选择<b style='color:#F56C6C'>统计项目</b>。", "提示", { dangerouslyUseHTMLString: true, type: "info" });
              this.$refs.countitem.focus();
              return false;
          }
          this.OtherShow = false;
          this.tableColumn = [];
          this.otherTableColumn = [];
          let field = this.infocode.split(",");
          let title = this.infoitem.split(",");
          field.forEach((item) => {
              if (!!item) {
                  let data = this.defaultColumn.find((m) => m.field == item);
                  if (!!data) {
                      this.tableColumn.push(data);
                      if (data.field == "rp_pat_name") {
                          this.tableColumn.push({ title: "病历号", field: "rp_pat_no", width: "130", position: "left" });
                      }
                  }
              }
          });
          if (this.otherTAT.cp_tatsmpd2send == "1") this.otherTableColumn.push(this.defaultColumn.find((m) => m.field == "cp_tatsmpd2send"));
          if (this.otherTAT.cp_tatsend2arr == "1") this.otherTableColumn.push(this.defaultColumn.find((m) => m.field == "cp_tatsend2arr"));
          if (this.otherTAT.cp_tatarr2rcv == "1") this.otherTableColumn.push(this.defaultColumn.find((m) => m.field == "cp_tatarr2rcv"));
          if (this.otherTAT.cp_tatreceive2input == "1") this.otherTableColumn.push(this.defaultColumn.find((m) => m.field == "cp_tatreceive2input"));
          if (this.otherTAT.cp_tatinput2report == "1") this.otherTableColumn.push(this.defaultColumn.find((m) => m.field == "cp_tatinput2report"));
          if (this.otherTAT.cp_tatreq2report == "1") this.otherTableColumn.push(this.defaultColumn.find((m) => m.field == "cp_tatreq2report"));
          this.bLoading = true;
          this.$tool
              .request({
                  url: "LIS/LIS6/LIS651",
                  method: "post",
                  timeout: 600000,
                  data: {
                      action: "query",
                      daytype: this.daytype, //标本日期(1) 报告日期(2)工作组签收日期(3)
                      infocode: this.infocode, //要查询的列数
                      sortArr: this.sortArr, //排序
                      ...this.searchobj,
                      ...this.otherTAT,
                  },
              })
              .then((res) => {
                  ++this.xTablekey;
                  this.tableData = res.data;
                  this.sampcnt = res.sampcnt;
                  this.avg = {
                      sampcnt: res.sampcnt,
                      avg_cp_sampled: res.avg_cp_sampled,
                      avg_cp_recieve: res.avg_cp_recieve,
                      avg_cp_report: res.avg_cp_report,
                      avg_samptorep: res.avg_samptorep,
                      avg_cp_tatsmpd2send: res.avg_tatsmpd2send,
                      avg_cp_tatsend2arr: res.avg_tatsend2arr,
                      avg_cp_tatarr2rcv: res.avg_tatarr2rcv,
                      avg_cp_tatreceive2input: res.avg_tatreceive2input,
                      avg_cp_tatinput2report: res.avg_tatinput2report,
                      avg_cp_tatreq2report: res.avg_tatreq2report,
                  };
                  this.bLoading = false;
              })
              .catch((e) => {
                  this.bLoading = false;
                  // this.$message.warning(e)
                  console.log("e", e);
              });
      },
      xTable1dblclick({ row, column }) {
          this[row.countcode] = false;
          try {
              var delrow = this.$refs.xTable1.getCurrentRow();
              if (delrow) {
                  var alld = this.$refs.xTable1.tableData;
                  var rowindex = alld.indexOf(delrow);
                  this.$refs.xTable1.remove(delrow);
                  let havedata = this.$refs.xTable1.tableData;
                  if (havedata.length > 0) {
                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                      let selectrow = havedata[rowindex];
                      this.$refs.xTable1.setCurrentRow(selectrow);
                  }
              }
          } catch (e) {
              console.log("error", e);
          }
      },
      formatFun({ cellValue, column, row }) {
          if (["rp_req_wardno"].includes(column.property)) {
              try {
                  let wardname = this.wardOption.find((m) => m.data == cellValue);
                  if (wardname != undefined && wardname != null) {
                      return wardname.display;
                  } else {
                      return cellValue;
                  }
              } catch {}
          } else if (["rp_req_deptno"].includes(column.property)) {
              try {
                  let deptname = this.deptOption.find((m) => m.data == cellValue);
                  if (deptname != undefined && deptname != null) {
                      return deptname.display;
                  } else {
                      return cellValue;
                  }
              } catch {}
          } else {
              return cellValue;
          }
      },
      footerCellClassName({ $rowIndex, column, columnIndex }) {
          if (!["rp_pat_name", "rp_pat_no", "rp_pat_typecode", "rp_req_wardno", "rp_req_deptno", "rp_specimen_code", "rp_req_itemname", "rp_req_groupna", "rp_sampleyear", "rp_samplemonth", "rp_sampleday"].includes(column.property)) {
              if (column.property == "cp_samplecnt") {
                  return "colcnt";
              } else {
                  return "colavg";
              }
          }
          if (columnIndex === 0) {
              if ($rowIndex === 0) {
                  return "colcnt";
              } else {
                  return "col-red";
              }
          }
      },
      footerMethod({ columns, data }) {
          return [
              columns.map((column, columnIndex) => {
                  if (columnIndex === 0) {
                      return "平均总计";
                  }
                  if (!["rp_pat_name", "rp_pat_no", "rp_pat_typecode", "rp_req_wardno", "rp_req_deptno", "rp_specimen_code", "rp_req_itemname", "rp_req_groupna", "rp_sampleyear", "rp_samplemonth", "rp_sampleday"].includes(column.property)) {
                      if (column.property == "cp_samplecnt") {
                          return this.avg.sampcnt;
                      }
                      if (column.property == "cp_sampled") {
                          return this.avg.avg_cp_sampled;
                      }
                      if (column.property == "cp_recieve") {
                          return this.avg.avg_cp_recieve;
                      }
                      if (column.property == "cp_report") {
                          return this.avg.avg_cp_report;
                      }
                      if (column.property == "samptorep") {
                          return this.avg.avg_samptorep;
                      }
                      if (column.property == "cp_tatsmpd2send") {
                          return this.avg.avg_cp_tatsmpd2send;
                      }
                      if (column.property == "cp_tatsend2arr") {
                          return this.avg.avg_cp_tatsend2arr;
                      }
                      if (column.property == "cp_tatarr2rcv") {
                          return this.avg.avg_cp_tatarr2rcv;
                      }
                      if (column.property == "cp_tatreceive2input") {
                          return this.avg.avg_cp_tatreceive2input;
                      }
                      if (column.property == "cp_tatinput2report") {
                          return this.avg.avg_cp_tatinput2report;
                      }
                      if (column.property == "cp_tatreq2report") {
                          return this.avg.avg_cp_tatreq2report;
                      }
                  }
                  return null;
              }),
          ];
      },
      CellClassName({ row, rowIndex, column, columnIndex }) {
          if (!["rp_pat_name", "rp_pat_no", "rp_pat_typecode", "rp_req_wardno", "rp_req_deptno", "rp_specimen_code", "rp_req_itemname", "rp_req_groupna", "rp_sampleyear", "rp_samplemonth", "rp_sampleday"].includes(column.property)) {
              if (column.property == "cp_samplecnt") {
                  return "colcnt";
              } else {
                  return "colavg";
              }
          }
      },
      tableClear() {
          this.rp_pat_name = false;
          this.rp_pat_no = false;
          this.rp_pat_typecode = false;
          this.rp_req_deptno = false;
          this.rp_req_wardno = false;
          this.rp_specimen_code = false;
          this.rp_req_itemname = false;
          this.rp_req_groupna = false;
          this.rp_sampleyear = false;
          this.rp_samplemonth = false;
          this.rp_sampleday = false;
          this.tableData1 = [];
      },
      dialogcountItemsave() {
          let data = this.$refs.xTable1.tableData;
          let res1 = "";
          let res2 = "";
          if (data.length > 0) {
              data.forEach((element) => {
                  if (res2 == "") {
                      res2 = element.countitem;
                      res1 = element.countcode;
                  } else {
                      res2 += "," + element.countitem;
                      res1 += "," + element.countcode;
                  }
              });
          }
          this.infoitem = res2;
          this.infocode = res1;
          this.dialogcountItem = false;
      },
  },
};
</script>

<style scoped>
table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
  white-space: nowrap;
}
.pagetop {
  width: 100%;
  height: 120px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 125px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 0px;
  right: 0px;
  overflow: auto;
}
.el-checkbox__label {
  padding: 0px;
}
.left_nav {
  width: 20%;
  height: 100%;
  border-right: 1px solid #ccc;
  padding: 0px 0px 0px 0px;
  float: left;
  display: inline;
}
.left_nav div {
  cursor: pointer;
  height: 40px;
  width: 100%;
  float: left;
  padding-left: 20px;
  line-height: 40px;
}
.left_nav .active {
  background-color: DeepSkyBlue;
}
.right_nav {
  width: 80%;
  height: 100%;
  display: inline-block;
  vertical-align: top;
  float: left;
  display: inline;
}
.table1style tr td {
  padding: 0px 2px 0px 5px;
}
::v-deep.mytable-style .vxe-body--row.row-blue {
  color: rgb(157, 158, 161) !important;
  font-weight: bold;
}
::v-deep.el-checkbox__label {
  padding-left: 0px;
}

::v-deep.el-icon-time {
  line-height: 18px !important;
}
::v-deep.el-range__close-icon {
  line-height: 18px !important;
}
::v-deep.el-range-editor--small .el-range-separator {
  line-height: 17px !important;
}
::v-deep .el-input--suffix .el-input__inner {
  padding-right: 0px;
}
::v-deep .colcnt {
  background-color: #eee8aa !important;
}
::v-deep .colavg {
  background-color: #f0e68c !important;
}
::v-deep .el-checkbox__label {
  display: inline-block;
  font-size: 12px;
}
</style>
